random photo
#(Haley) Making Figures with Default Graphics and ggplot2
Gandrud outlines several useful chunk options for figures in R Markdown documents: - fig.path: This tells knitr where to save your figures by specifying a file path. - out.height and out.width: These set your figure’s output height and width. R Markdown uses pixels (ex. To set height to 200 pixels, use out.height=‘200px’). If you are using LaTeX, you can also specify the height or width using cm, in, or as a proportion of a page element (ex. To set width to 80% of the text width, use outwidth=‘0.8\textwidth’). - fig.align: This sets the alignment of your figure to left, center, or right. - fig.cap and fig.lb: These set your figure’s LaTeX caption and label.
Because we already have some experience with Base R’s plotting functions, this section serves as a little refresh on how to do some basic plotting before we get into “fancy” plotting with ggplot2. Every time you create a new R Markdown document, you probably have noticed the inclusion of the pressure plot code chunk. That is exactly how to plot in Base R!
#taking a look at what the pressure data is
summary(pressure)
## temperature pressure
## Min. : 0 Min. : 0.0002
## 1st Qu.: 90 1st Qu.: 0.1800
## Median :180 Median : 8.8000
## Mean :180 Mean :124.3367
## 3rd Qu.:270 3rd Qu.:126.5000
## Max. :360 Max. :806.0000
#plotting the pressure data
plot(pressure)
Let’s try this again with some very unscientific fake data on different dogs’ fetch abilities and “goodness” ratings. For now, we will focus on their fetch abilities. Let’s start by loading the data file and checking it out.
#load and view data
GoodDogs <- read_csv("GoodDogs.csv")
##
## ── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────
## cols(
## Dog = col_double(),
## Breed = col_character(),
## Age = col_double(),
## Fetch_Time = col_double(),
## Fetch_Distance = col_double(),
## Rating = col_double(),
## Good = col_double()
## )
View(GoodDogs)
Now that we can see we have data on both fetch time and fetch distance, let’s make a scatterplot, assuming that time is dependent on the distance the ball is thrown (and not on how fast a dog is or its focus on the task at hand).
plot(GoodDogs$Fetch_Distance, GoodDogs$Fetch_Time)
Now that we have the basic scatterplot down, let’s clean up our axis labels and add a title. We can do this by specifying the xlab, ylab, and main arguments in the plot() function.
plot(GoodDogs$Fetch_Distance, GoodDogs$Fetch_Time,
xlab = "Distance Ball is Thrown (ft)",
ylab = "Fetch Time (s)",
main = "Throw Distance vs Time while Playing Fetch")
Most of the time
#(Molly) Exercise 2: Networks #(Paige) Exercise 3: Introduction to phylogenies
Citations of all R packages used to generate this report.
library("knitcitations")
cleanbib()
options("citation_format" = "pandoc")
read.bibtex(file = "packages.bib")
[1] E. Paradis, S. Blomberg, B. Bolker, et al. ape: Analyses of Phylogenetics and Evolution. R package version 5.4-1. 2020. <URL: http://ape-package.ird.fr/>.
[2] E. Paradis and K. Schliep. “ape 5.0: an environment for modern phylogenetics and evolutionary analyses in R”. In: Bioinformatics 35 (2019), pp. 526-528.
[3] R Core Team. R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. Vienna, Austria, 2020. <URL: https://www.R-project.org/>.
[4] H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016. ISBN: 978-3-319-24277-4. <URL: https://ggplot2.tidyverse.org>.
[5] H. Wickham, W. Chang, L. Henry, et al. ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. R package version 3.3.2. 2020. <URL: https://CRAN.R-project.org/package=ggplot2>.
[6] H. Wickham and J. Hester. readr: Read Rectangular Text Data. R package version 1.4.0. 2020. <URL: https://CRAN.R-project.org/package=readr>.
Version information about R, the operating system (OS) and attached or R loaded packages. This appendix was generated using sessionInfo().
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Catalina 10.15.5
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitcitations_1.0.10 readr_1.4.0 ggplot2_3.3.2
## [4] ape_5.4-1
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.5 plyr_1.8.6 pillar_1.4.6 compiler_4.0.2
## [5] highr_0.8 tools_4.0.2 digest_0.6.25 lubridate_1.7.9
## [9] jsonlite_1.7.1 evaluate_0.14 lifecycle_0.2.0 tibble_3.0.3
## [13] gtable_0.3.0 nlme_3.1-149 lattice_0.20-41 pkgconfig_2.0.3
## [17] rlang_0.4.8 bibtex_0.4.2.3 rstudioapi_0.11 cli_2.0.2
## [21] yaml_2.2.1 parallel_4.0.2 xfun_0.18 xml2_1.3.2
## [25] httr_1.4.2 RefManageR_1.2.12 withr_2.3.0 stringr_1.4.0
## [29] dplyr_1.0.2 knitr_1.30 generics_0.0.2 vctrs_0.3.4
## [33] hms_0.5.3 grid_4.0.2 tidyselect_1.1.0 glue_1.4.2
## [37] R6_2.4.1 fansi_0.4.1 rmarkdown_2.4 purrr_0.3.4
## [41] magrittr_1.5 scales_1.1.1 ellipsis_0.3.1 htmltools_0.5.0
## [45] assertthat_0.2.1 colorspace_1.4-1 stringi_1.5.3 munsell_0.5.0
## [49] crayon_1.3.4